package bsc.war.form;

import bsc.ejb.entity.Pointer;
import bsc.ejb.entity.Settings;
import bsc.ejb.metadata.Comparation;
import bsc.ejb.metadata.Framework;
import bsc.war.delegate.DelegateBSC;
import bsc.war.factory.Factory;
import bsc.war.service.BSCUtils;
import bsc.war.service.ScoreCardUtils;
import java.util.Date;
import java.util.List;
import java.util.StringTokenizer;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

//org.apache.commons.validator.GenericValidator
/**
 *
 * @author Miguel Angel
 */
public class CalculateDataExtend extends AbstractController {

    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        boolean result = true;// = "Actualización de Datos Exitosa";
        try {

            DelegateBSC delegate = (DelegateBSC) Factory.getBean("DelegateBSC");
            processRequestInternal(request, response, delegate);
            
        } catch (Exception e) {
            e.printStackTrace();
            result = false;
        }
        request.setAttribute("result", result);
        return new ModelAndView("result");
    }

    public static void processRequestInternal(HttpServletRequest request,
            HttpServletResponse response, DelegateBSC delegate) {

        Framework framework = delegate.findFramework(Boolean.TRUE);

        Long idPointer = Long.parseLong(request.getParameter("scoreCard"));

        Pointer pointer = (Pointer) delegate.findScoreCard(idPointer);
        Settings settings = pointer.getSettings();

        List<Comparation> comparations = delegate.findComparation(framework, Boolean.TRUE);

       
        if (settings.getOperationData() == Settings.OperationData.CONSOLIDATESUM || settings.getOperationData() == Settings.OperationData.CONSOLIDATEAVG) {
            for (Comparation comparation : comparations) {
               /* if (BSCUtils.isParentComparatorDimenalCutExecutable(delegate, pointer, comparation, startDate, endDate)) {
                    BSCUtils.setParentComparatorDimensionalCut(delegate, pointer, comparation, startDate, endDate);
                }*/
            }
        } 

    }
}
